"""
Python中异常的完整格式如下：

    try:
        可能出现问题的代码
    except [Exception as e:]
        出现问题后的解决方案
    else:
        只能在try中没有问题，就会执行这里
        只要在try中有问题，就会跳过这里的代码
    finally:
        无论try 是否有问题，都会执行这里，一般用于释放资源
"""

# 演示 文件拷贝
try:
    with open('a/demo06_full.py', 'rb') as fr,open('demo06_full[备份].py', 'wb') as fw:
        fw.write(fr.read())
except Exception as e:
    print(e)


# fr = None
# fw = None
# try:
#     fr = open('a/demo06_full.py', 'rb')
#     fw = open('demo06_full[备份].py', 'wb')
# except Exception as e:
#     print(f'发生了异常:{e}')
# else:
#     # 具体业务逻辑
#     fw.write(fr.read())
# finally:
#     try:
#         fw.close()
#     except Exception as e:
#         print(e)
#     try:
#         fr.close()
#     except Exception as e:
#         print(e)

# 演示捕获异常的完整放啊是
# try:
#     print('try---1')
#     # print(10/0)
#     print(10/2)
#     print('try--2')
# except Exception as e:
#     print(f'程序出现了异常:{e}')
# else:
#     print('这里是else,看我执行了码？')
# finally:
#     print('这里是finally,看我执行了码？')
